package com.lagou.dao;/*
 *Author:cxz
 *@Date:${Date}
 */

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lagou.dao.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select email ,password from cxz_users where email=#{username} ")
    public User getUser(String username);

    @Insert(" insert into cxz_token (token,email)values(#{token},#{email})")
    public void saveToken(@Param("token") String token, @Param("email") String email);

    @Insert("insert into cxz_cod (email,code)values(#{email},#{code})")
    public void saveCode(@Param("email") String email, @Param("code") String code);

    @Select("select code from cxz_cod where email=#{email}" +
            "  and  UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(create_time)<10*60 order by create_time desc limit 1 ")
    public String getCodeByEmail(String email);

    @Select("select email from cxz_token where token=#{token}")
    public String getEmailBytoken(String token);

    @Insert("insert into cxz_users (email,password)values(#{email},#{password})")
    public void insertUser(User user);


}
